using System.Numerics;
using TTEngine.Graphics;
using TTEngine.TTMath;

namespace TTEngine.Graphics
{
    public class Camera
    {
        public void Apply()
        {
            TTEngine.Runtime.activeCamera = this;
        }
        public Vector2 LookAt { get; set; } = Vector2.Zero;
        public float Scale { get; set; } = 1.0f;
        public SizeRect? LimitRect { get; set; } = null;
        
        private float[] _viewMatrix = new float[16];
        private float[] _projMatrix = new float[16];

        public float[] GetViewMatrix()
        {
            float sx = Scale;
            float sy = Scale;
            float offx = -(int)LookAt.X;
            float offy = -(int)LookAt.Y;

            _viewMatrix[0] = sx; _viewMatrix[4] = 0; _viewMatrix[8] = 0; _viewMatrix[12] = offx * sx;
            _viewMatrix[1] = 0; _viewMatrix[5] = sy; _viewMatrix[9] = 0; _viewMatrix[13] = offy * sy;
            _viewMatrix[2] = 0; _viewMatrix[6] = 0; _viewMatrix[10] = 1; _viewMatrix[14] = 0;
            _viewMatrix[3] = 0; _viewMatrix[7] = 0; _viewMatrix[11] = 0; _viewMatrix[15] = 1;

            return _viewMatrix;
        }
    }
}